﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Drawing.Imaging;
using TeenyGrab.Interfaces;
using TeenyGrab.Objects;
using TeenyGrab.Windows;
using TeenyGrab.Helpers;
using TeenyGrab.Serialization;

namespace TeenyGrab.Outputs
{
    [Serializable]
    public class FileOutput : IOutput
    {
        public string FilePath { get; set; }
        public SerializableImageFormat Format { get; set; }
        public bool Configurable { get { return true; } set { } }

        public string Name { get { return "File"; } set { } }

        public string Description { get { return "Saves the image to a file."; } set { } }


        public FileOutput()
        {
            FilePath = "";
            Format = new SerializableImageFormat(ImageFormat.Jpeg);
        }

        private string GetDateAsFileName()
        {
            var date = DateTime.Now;
            return date.ToString("yyyy-MM-dd_HH-mm-ss");
        }

        public void Configure()
        {
            var configure = new ConfigureFileOutputWindow(this);
            configure.ShowDialog();
        }

        public void Put(ImageObject image)
        {
            var extension = Format.Format.GetExtension();
            image.Image.Save(FilePath + GetDateAsFileName() + "." + extension, Format.Format);
        }
    }
}
